package t20240516_lineage;

import java.util.List;

public class Test4 {


    public static void main(String[] args) {


        String sql = "create table users (\n" +
                "    `user_id` int,\n" +
                "    proctime as proctime()\n" +
                ") with (\n" +
                "    'connector' = 'datagen',\n" +
                "    'rows-per-second'='100',\n" +
                "    'fields.user_id.kind'='random',\n" +
                "    'fields.user_id.min'='1',\n" +
                "    'fields.user_id.max'='10'\n" +
                ");\n" +
                "\n" +
                "create table users_pv (\n" +
                "    `stime` string,\n" +
                "    `pv` bigint\n" +
                ") with(\n" +
                "    'connector' = 'blackhole'\n" +
                ");\n" +
                "\n" +
                "insert into users_pv \n" +
                "select \n" +
                "    date_format(proctime, 'yyyy-MM-dd') as stime, \n" +
                "    count(*) as pv\n" +
                "from users \n" +
                "group by date_format(proctime, 'yyyy-MM-dd')";

        TaskSource taskSource = new TaskSource(sql);
        List<TaskSource.SplitSource> split = taskSource.split();
        for (TaskSource.SplitSource splitSource : split) {
            System.out.println(splitSource.getStartLineNumber() + "  " +  splitSource.getSqlSource());
        }

    }
}
